﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace eventr.View
{
    public partial class IE8Popup : UserControl
    {
        public IE8Popup()
        {
            InitializeComponent();
            if (HtmlPage.IsEnabled)
            {   
                string version = HtmlPage.BrowserInformation.UserAgent;

                //Ensure the user is on IE8, otherwise show the link to get IE8
                if (version.IndexOf("MSIE 8.0") != -1)
                {
                    gridNotIE8.Visibility = Visibility.Collapsed;
                }
                else
                {
                    gridIsIE8.Visibility = Visibility.Collapsed;
                }
            }
        }

        public void Show()
        {
            VisualStateManager.GoToState(this, "Out", true);
        }

        public void Close()
        {
            VisualStateManager.GoToState(this, "In", true);
        }
        

        private void btnInstallSlice_Click(object sender, RoutedEventArgs e)
        {
            //Slices can only be added from a user initiated event in the browser
            //they must first click a button in the HTML page (not Silverlight) before 
            //it will install. This will pop up a HTML window for the user to click.
            HtmlPage.Window.Invoke("showIE8SlicePopup");
            Close();
        }

        private void btnInstallIE8_Click(object sender, RoutedEventArgs e)
        {
            HtmlPage.Window.Navigate(new Uri("http://www.microsoft.com/windows/internet-explorer/default.aspx", UriKind.Absolute), "_blank");
            Close();
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
